package engine.control
{
	import flash.display.DisplayObject;
	import flash.display.InteractiveObject;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.filters.GlowFilter;
	
	
	/**
	 * 闪动发光 
	 * @author liuel
	 * 
	 */	
	public class GlowTween
		
	{
		
		private var _target:DisplayObject;
		
		private var _color:uint;
		
		private var _toggle:Boolean;
		
		private var _blur:Number;
		
		
		
		public function GlowTween(color:uint=0xFFFFFF)
			
		{
			
			_color=color;
			
			_toggle=true;
			
			_blur=2;
			
			
		}
		public function startGlowHandler(traget:DisplayObject):void
		{
			_target =traget
			traget.addEventListener(Event.ENTER_FRAME, blinkHandler, false, 0, true);
			
		}
		public function remove():void
			
		{
			_target.removeEventListener(Event.ENTER_FRAME, blinkHandler);
			
			_target.filters=null;
			
			_target=null;
			
		}
		
	
		
		
		
		public function stopGlowHandler(traget:DisplayObject):void
			
		{
			
			traget.removeEventListener(Event.ENTER_FRAME, blinkHandler);
			
			traget.filters=null;
			
		}
		
		public function get isGlow():Boolean
		{
			if(_target.filters == null)
			{
				return false;
			}
			else
			{
				return true;
			}
		}
		
		private function blinkHandler(evt:Event):void
		{
			
			if (_blur >= 20)
				
				_toggle=false;
				
			else if (_blur <= 2)
				
				_toggle=true;
			
			_toggle ? _blur+=5 : _blur-=5;
			
			var glow:GlowFilter=new GlowFilter(_color, 1, _blur, _blur, 4, 4);
			
			_target.filters=[glow];
			
		}
		
	}
}